function Ui() {

	var menuItemsHolder = null;

	var selectedMenuItem = null;

	this.init = function() {
		ui.initMenu();
	};

	this.drawErrors = function(errors, placeAt) {
		if (errors.length == 0) {
			return;
		}

		var divElement, pElement, brElement;

		divElement = $(placeAt);
		divElement.empty();

		pElement = $(document.createElement("p"));
		pElement.attr("style", "color: red;");

		for ( var index = 0; index < errors.length; index++) {
			if (index > 0) {
				brElement = $(document.createElement("br"));

				pElement.append(brElement);
			}

			pElement.append(main.getErrorMessage(errors[index]));
		}

		divElement.append(pElement);
		divElement.show();
	};

	var ui = {};

	ui.initMenu = function() {
		var placeHolder = $("#menu");

		// cleans the content
		placeHolder.empty();

		var pElement, ulElement, liElement, aElement, spanElement, menuItem, child, id;

		menuItemsHolder = new Object();

		for ( var index = 0; index < menuItems.length; index++) {
			menuItem = menuItems[index];

			if (menuItem.children.length == 0) {
				continue;
			}

			pElement = $(document.createElement("p"));
			pElement.html(menuItem.label);

			placeHolder.append(pElement);

			ulElement = $(document.createElement("ul"));

			for ( var index2 = 0; index2 < menuItem.children.length; index2++) {
				child = menuItem.children[index2];

				id = "menuItem-" + index + "-" + index2;

				aElement = $(document.createElement("a"));
				aElement.attr("id", id);
				aElement.attr("href", child.href);
				aElement.text(child.label);
				aElement.click(function(event) {
					event.preventDefault();

					$("#innerContent").empty();
					$("#loading").show();

					if (selectedMenuItem != null) {
						// selectedMenuItem.a.show();
						// selectedMenuItem.span.hide();
					}

					var id = $(this).attr("id");
					var url = $(this).attr("href");

					$.get(url, function(data) {
						$("#innerContent").html(data);
					});

					selectedMenuItem = menuItemsHolder[id];
					// selectedMenuItem.a.hide();
					// selectedMenuItem.span.show();
				});

				spanElement = $(document.createElement("span"));
				spanElement.attr("style", "display: none; color: red;");
				spanElement.text(child.label);

				liElement = $(document.createElement("li"));
				liElement.append(aElement);
				liElement.append(spanElement);

				ulElement.append(liElement);

				menuItemsHolder[id] = {
					a : aElement,
					span : spanElement
				};
			}

			placeHolder.append(ulElement);
		}
	};

}
